package com.bawei.lib_common.manager

import android.util.Log
import com.bawei.lib_net.RetrofitFactory
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch

/**
 * 用户数据管理器
 * 用于在用户登录后获取相关数据
 */
object UserDataManager {
    
    private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
//    private val shopApi: ShopApiService by lazy {
//        RetrofitFactory.getRetrofitFactory().create(ShopApiService::class.java)
//    }
    
    /**
     * 用户登录后初始化数据
     */
    fun initUserData() {
        scope.launch {
            try {
                // 获取购物车数量
//                getCartCount()
                // 获取收藏数量
//                getCollectCount()
            } catch (e: Exception) {
                Log.e("UserDataManager", "初始化用户数据失败: ${e.message}")
            }
        }
    }
    
    /**
     * 获取购物车数量
     */
//    private suspend fun getCartCount() {
//        try {
////            val response = shopApi.getShopNumber()
////            if (response.code == 200) {
////                GlobalDataManager.updateCartCount(response.data)
////                Log.d("UserDataManager", "获取购物车数量成功: ${response.data}")
////            }
////        } catch (e: Exception) {
////            Log.e("UserDataManager", "获取购物车数量失败: ${e.message}")
//        }
//    }
    
    /**
     * 获取收藏数量
     */
//    private suspend fun getCollectCount() {
//        try {
//            val response = shopApi.getCollect()
//            if (response.code == 200) {
//                val collectCount = response.data?.records?.size ?: 0
//                GlobalDataManager.updateCollectCount(collectCount)
//                Log.d("UserDataManager", "获取收藏数量成功: $collectCount")
//            }
//        } catch (e: Exception) {
//            Log.e("UserDataManager", "获取收藏数量失败: ${e.message}")
//        }
//    }
} 